package com.bos.web.action;

import com.bos.domian.system.Role;
import com.bos.service.RolesService;
import com.bos.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * @author misterWei
 * @create 2019年01月13号:21点42分
 * @mailbox mynameisweiyan@gmail.com
 */
@ParentPackage("json-default")
@Actions
@Controller
@Namespace("/")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RoleAction extends BaseAction<Role> {

    @Autowired
    private RolesService rolesService;

    /**
     * 菜单ID的接收  以,分隔 有可能为null
     *
     * */
    private String menuArray;

    public void setMenuArray(String menuArray) {
        this.menuArray = menuArray;
    }

    public void setPermissionIds(String[] permissionIds) {
        this.permissionIds = permissionIds;
    }

    /**

     * 菜单ID的接收  以数组 有可能为null
     *
     * */

    private String[] permissionIds;

    @Action(value = "role_list",results = {@Result(name = "success",type = "json")})
    public String roleList(){
        List<Role> roleList = rolesService.findAll();
        ActionContext.getContext().getValueStack().push(roleList);
        return SUCCESS;
    }

    @Action(value = "role_save",results = {@Result(name = "success",type = "redirect",location = "pages/system/role.html")})
    public String roleAdd(){
        rolesService.save(menuArray,model,permissionIds);
        return SUCCESS;
    }
}
